<?php   include_once(dirname(__FILE__).'/include/config.inc.php');


$param = [
        'realname'  =>  isset($_POST['realname'])?$_POST['realname']:null,
        'sex'  =>  isset($_POST['sex'])?$_POST['sex']:1,
        'job'  =>  isset($_POST['job'])?$_POST['job']:null,
        'tel'  =>  isset($_POST['tel'])?$_POST['tel']:null,
        'minzu'  =>  isset($_POST['minzu'])?$_POST['minzu']:null,
        'aid'  =>  isset($_POST['aid'])?$_POST['aid']:null,
        'ajob'  =>  isset($_POST['ajob'])?$_POST['ajob']:null,
        'address'  =>  isset($_POST['address'])?$_POST['address']:null,
        'content'  =>  isset($_POST['content'])?$_POST['content']:null,
];

if(is_null($param['realname'])){
    ShowMsg('请填写姓名');
    exit();
}
if(is_null($param['tel'])){
    ShowMsg('请填写联系方式');
    exit();
}
if(is_null($param['aid'])){
    ShowMsg('请选择申请协会');
    exit();
}
if(is_null($param['address'])){
    ShowMsg('请填写住址');
    exit();
}
if(is_null($param['content'])){
    ShowMsg('请填写艺术简介');
    exit();
}

foreach ($param as $k =>$v){
    if($k == 'sex'){
        $param[$k] = (int)$v;
    }elseif( $k == 'aid'){
        $sql = "SELECT * FROM `#@__infolist` WHERE id =  ".(int)$v;
         $dosql->Execute($sql);
         $row = $dosql->getArray();
         if(is_null($row)){
             ShowMsg('请选择正确的协会！','index.php');
             exit();
         }
         $param[$k] = (int)$v;
         $aname = $row['title'];

    }else{
        $v = htmlspecialchars($v);
        $v = trim($v);
        $param[$k] = $v;
    }

}
$param['aname'] = $aname;
$param['ip']       = gethostbyname($_SERVER['REMOTE_ADDR']);
	
	
		$sql = "INSERT INTO `#@__applyuser` ( realname, sex, job, tel, minzu, aid, aname, ajob,address,content, ip) VALUES ( '".
            $param['realname']."','".
            $param['sex']."','".
            $param['job']."','".
            $param['tel']."','".
            $param['minzu']."','".
            $param['aid']."','".
            $param['aname']."','".
            $param['ajob']."','".
            $param['address']."','".
            $param['content']."','".
            $param['ip']  ."')";
		if($dosql->ExecNoneQuery($sql))
		{
            ShowMsg('申请成功。请等待客服联系！','index.php');
            exit();
		}

